package com.benio.ycfdisplayer.imageloader;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Handler;

import com.benio.ycfdisplayer.displayer.Options;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.BitmapDisplayer;
import com.nostra13.universalimageloader.core.process.BitmapProcessor;

/**
 * {@link UILDisplayer}加载配置
 * Created by zhangzhibin on 2016/9/2.
 */
public class UILDisplayOptions extends Options {
    public final Drawable emptyUriImage;
    public final boolean resetViewBeforeLoading;
    public final boolean cacheInMemory;
    public final boolean cacheOnDisk;
    public final ImageScaleType imageScaleType;
    public final BitmapFactory.Options decodingOptions;
    public final int delayBeforeLoading;
    public final boolean considerExifParams;
    public final Object extraForDownloader;
    public final BitmapProcessor preProcessor;
    public final BitmapProcessor postProcessor;
    public final BitmapDisplayer displayer;
    public final Handler handler;

    public UILDisplayOptions(Builder builder) {
        super(builder);
        emptyUriImage = builder.emptyUriImage;
        resetViewBeforeLoading = builder.resetViewBeforeLoading;
        cacheInMemory = builder.cacheInMemory;
        cacheOnDisk = builder.cacheOnDisk;
        imageScaleType = builder.imageScaleType;
        decodingOptions = builder.decodingOptions;
        delayBeforeLoading = builder.delayBeforeLoading;
        considerExifParams = builder.considerExifParams;
        extraForDownloader = builder.extraForDownloader;
        preProcessor = builder.preProcessor;
        postProcessor = builder.postProcessor;
        displayer = builder.displayer;
        handler = builder.handler;
    }

    public static class Builder extends Options.Builder {
        private Drawable emptyUriImage = null;
        private boolean resetViewBeforeLoading = false;
        private boolean cacheInMemory = false;
        private boolean cacheOnDisk = false;
        private ImageScaleType imageScaleType = ImageScaleType.IN_SAMPLE_POWER_OF_2;
        private BitmapFactory.Options decodingOptions;
        private int delayBeforeLoading = 0;
        private boolean considerExifParams = false;
        private Object extraForDownloader = null;
        private BitmapProcessor preProcessor = null;
        private BitmapProcessor postProcessor = null;
        private BitmapDisplayer displayer;
        private Handler handler = null;

        @Override
        public Builder setFailureImage(Drawable failureImage) {
            return (Builder) super.setFailureImage(failureImage);
        }

        @Override
        public Builder setPlaceHolderImage(Drawable placeHolderImage) {
            return (Builder) super.setPlaceHolderImage(placeHolderImage);
        }

        public Builder setEmptyUriImage(Drawable drawable) {
            emptyUriImage = drawable;
            return this;
        }

        public Builder resetViewBeforeLoading(boolean resetViewBeforeLoading) {
            this.resetViewBeforeLoading = resetViewBeforeLoading;
            return this;
        }

        public Builder cacheInMemory(boolean cacheInMemory) {
            this.cacheInMemory = cacheInMemory;
            return this;
        }

        public Builder cacheOnDisk(boolean cacheOnDisk) {
            this.cacheOnDisk = cacheOnDisk;
            return this;
        }

        public Builder imageScaleType(ImageScaleType imageScaleType) {
            this.imageScaleType = imageScaleType;
            return this;
        }

        public Builder bitmapConfig(Bitmap.Config bitmapConfig) {
            if (bitmapConfig == null) {
                return this;
            }
            if (decodingOptions == null) {
                decodingOptions = new BitmapFactory.Options();
            }
            decodingOptions.inPreferredConfig = bitmapConfig;
            return this;
        }

        public Builder decodingOptions(BitmapFactory.Options decodingOptions) {
            this.decodingOptions = decodingOptions;
            return this;
        }

        public Builder delayBeforeLoading(int delayInMillis) {
            this.delayBeforeLoading = delayInMillis;
            return this;
        }

        public Builder extraForDownloader(Object extra) {
            this.extraForDownloader = extra;
            return this;
        }

        public Builder considerExifParams(boolean considerExifParams) {
            this.considerExifParams = considerExifParams;
            return this;
        }

        public Builder preProcessor(BitmapProcessor preProcessor) {
            this.preProcessor = preProcessor;
            return this;
        }

        public Builder postProcessor(BitmapProcessor postProcessor) {
            this.postProcessor = postProcessor;
            return this;
        }

        public Builder displayer(BitmapDisplayer displayer) {
            this.displayer = displayer;
            return this;
        }

        public Builder handler(Handler handler) {
            this.handler = handler;
            return this;
        }

        @Override
        public UILDisplayOptions build() {
            return new UILDisplayOptions(this);
        }
    }
}